<template>
	<view>
		<!-- <navigator :url="`../goods_dedail/goods_dedail?id=${item.goods_id}`" class="listItem" v-for="item in goodsList" :key="item.goods_id">
			<view class="left">
				<image :src="item.goods_small_logo" mode=""></image>
			</view>
			<view class="right">
				<view class="r_top go_wrap">
					{{item.goods_name}}
				</view>
				<view class="r_bottom">￥{{item.goods_price | format_price}}</view>
			</view>
		</navigator> -->
		<goodsListItem @click="go_goods_dataile" :item="item" v-for="item in goodsList" :key="item.goods_id"></goodsListItem>
		<view v-if="isover" class="end_box">
			---我也是有底线的---
		</view>
	</view>
</template>

<script>
	import goodsListItem from '../../components/goodsListItem/goodsListItem.vue'
	export default {
		data() {
			return {
				goods_list_req_obj: {
					query: '',
					cid: '',
					pagenum: 1,
					pagesize: 10
				},
				goodsList: [],
				goods_total: 0,
				isover: false,
				isOn_req: false
			};
		},
		methods: {
			async get_goods_list_req(callback) {
				this.isOn_req = true;
				this.isover = false;
				const {data: res} = await uni.$http.get('/api/public/v1/goods/search', this.goods_list_req_obj);
				this.goods_total = res.message.total;
				this.goodsList = [...this.goodsList, ...res.message.goods];
				if(res) {
					callback && callback()
					this.isOn_req = false
				}
			},
			go_goods_dataile(goods_id) {
				uni.navigateTo({
					url: `../goods_dedail/goods_dedail?id=${goods_id}`
				})
			}
		},
		onLoad({query, cid}) {
			this.goods_list_req_obj.query = query || '';
			this.goods_list_req_obj.cid = cid || '';
			// 调用函数请求数据
			this.get_goods_list_req()
		},
		onPullDownRefresh() {
			this.goods_list_req_obj.pagenum = 1;
			this.goodsList = [];
			this.isover = false;
			setTimeout(() => {
				this.get_goods_list_req(() => {
					uni.stopPullDownRefresh();
				});
			}, 600)
		},
		onReachBottom() {
			if(this.isOn_req) return;
			console.log(this.isOn_req)
			if(this.goods_total === 0 || (this.goods_list_req_obj.pagenum * this.goods_list_req_obj.pagesize < this.goods_total)){
				this.goods_list_req_obj.pagenum ++;
				this.get_goods_list_req();
			}else {
				return this.isover = true;
			}
			
		},
		components: {
			goodsListItem
		}
	}
</script>

<style lang="scss">
.listItem {
	border-bottom: 2px solid #CCCCCC;
	display: flex;
	height: 250rpx;
	padding: 20rpx 10rpx;
	box-sizing: border-box;
	.left {
		width: 30%;
		height: 100%;
		flex-shrink: 0;
		image {
			width: 100%;
			height: 100%;
		}
	}
	.right {
		height: 100%;
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		box-sizing: border-box;
		margin-left: 10rpx;
		.r_bottom {
			color: #bc0000;
		}
	}
}
.end_box {
	margin-top: 40rpx;
	text-align: center;
}
</style>
